<template>
	<div class="port-page">
		<!-- 顶部按钮 -->
		<el-tabs v-model="activeName" style="margin-top: 30px;" type="card" @tab-click='tabchk'>
			<el-tab-pane label="全校出勤率" name="quanxiao"></el-tab-pane>
			<el-tab-pane label="老师出勤率" name="laoshi"></el-tab-pane>
			<el-tab-pane label="班级出勤率" name="banji"></el-tab-pane>
		</el-tabs>
		<div class="but1">
			<router-link to="/home">
				<el-button type="warning" size="small" class="add btn" style='margin-right: 10px;' icon="el-icon-menu">首页</el-button>
			</router-link>
			<el-date-picker v-if="sjshow" v-model="btime" type="date" style="line-height: 40px; width: 150px;"  placeholder="选择开始日期" value-format="yyyy-MM-dd">
			</el-date-picker>
			<el-date-picker v-if="sjshow" v-model="etime" type="date" style="line-height: 40px; width: 150px;"  placeholder="选择结束日期" value-format="yyyy-MM-dd">
			</el-date-picker>
			<!--<el-select v-model="Day"   placeholder="请选择">
				<el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
				</el-option>
			</el-select>-->
		
			 <el-button  icon="el-icon-search" v-if="sjshow"  type="primary" round size="small" style="margin-left: 20px;" @click="search('xxkq')"></el-button>
			 <!--<el-button  icon="el-icon-search" v-if="sjshow1" type="primary" round size="small" style="margin-left: 20px;" @click="search('lskq')"></el-button>
			 <el-button  icon="el-icon-search" v-if="sjshow2" type="primary" round size="small" style="margin-left: 20px;" @click="search('bjkq')"></el-button>-->
		</div>
		<!-- 模糊搜索条件 -->
		<!--<div style="width: 100%;text-align: center;font-size: 30px;float: left;margin-top: 20%;color: red;">-->
		<div id="kqtj1" v-if="sjshow" style="width: 100%;height: 400px;margin-top: 50px;"></div>
		<div id="kqtj2" v-if="sjshow1"style="width: 100%;height: 400px;margin-top: 50px;"></div>
		<div id="kqtj3" v-if="sjshow2"style="width: 100%;height: 400px;margin-top: 50px;"></div>
		<!--</div>-->
		<LoadingComponent v-show="isLoading"></LoadingComponent>
		<router-view class="port-view"></router-view>
	</div>
</template>
<script>
	import { mapState } from 'vuex'
	import LoadingComponent from 'components/loading'
	import echarts from 'echarts'
	import qs from 'qs'
	export default {
		props: ['params'],
		components: {
			LoadingComponent,
		},
		data() {
			return {
				Day:"1",
				sjshow: true,
				sjshow1: false,
				sjshow2: false,
				btime: '',
				etime: '',
				options: [{
					value: '1',
					label: 'D1'
				}, {
					value: '2',
					label: 'D2'
				}, {
					value: '3',
					label: 'D3'
				}, {
					value: '4',
					label: 'D4'
				}, {
					value: '5',
					label: 'D5'
				}, {
					value: '6',
					label: 'D6'
				}, {
					value: '7',
					label: 'D7'
				}, {
					value: '8',
					label: 'D8'
				}, {
					value: '9',
					label: 'D9'
				}, {
					value: '10',
					label: 'D10'
				}, {
					value: '11',
					label: 'D11'
				}, {
					value: '12',
					label: 'D12'
				}, {
					value: '13',
					label: 'D13'
				}, {
					value: '14',
					label: 'D14'
				}, {
					value: '15',
					label: 'D15'
				}, {
					value: '16',
					label: 'D16'
				}, {
					value: '17',
					label: 'D17'
				}, {
					value: '18',
					label: 'D18'
				}, {
					value: '19',
					label: 'D19'
				}, {
					value: '20',
					label: 'D20'
				}, {
					value: '21',
					label: 'D21'
				}, {
					value: '22',
					label: 'D22'
				}, {
					value: '23',
					label: 'D23'
				}, {
					value: '24',
					label: 'D24'
				}],
				sj: [],
				cqv: [],
				activeName: 'quanxiao',
				multipleDelNum: '', //获取批量选择的数据
				dataList: [], //表格数据
				comboxlist: [], //下拉框 动态的
				/*动画加载*/
				isLoading: true, //动画加载
				searchLoading: false, //搜索按钮触发按钮动画
				/*分页属性设置*/
				layout: 'total, sizes, prev, pager, next, jumper', //组件布局
				pageindex: this.$store.state.pageindex, //当前分页页码
				pagesizes: this.$store.state.pagesizes, //显示个数的选择器选项
				pagesize: this.$store.state.pagesize, //每页显示条目数
				total: 0, //总条数

				/*组件区域*/

				/*
				    prop :  接口参数名
				    label : 接口中文名
				    hide : 是否隐藏这一列
				    align : 这一列对齐顺序 ： left,right,center
				    headerAlign : 这一列表头对齐方式 ： left,right,center
				*/
			}
		},
		created() {
			//权限
			var logininfo = JSON.parse(localStorage.logininfo);
			//加载页面时调用
			this.$store.dispatch('changeTitle', '考勤统计'); //修改title
			this.$store.dispatch('changeRouterIndex', '/statistics/kqtj'); //修改路由
 			 var nowDate = new Date();
			 var year = nowDate.getFullYear();
			 var month = nowDate.getMonth() + 1 < 10 ? "0" + (nowDate.getMonth() + 1) : nowDate.getMonth() + 1;
			 var day = nowDate.getDate() < 10 ? "0" + nowDate.getDate() : nowDate.getDate();
			 var dateStr = year + "-" + month + "-" + day;
			 var dateStr1 = year + "-" + month + "-" + '01';
			 this.btime = dateStr1
			 this.etime = dateStr
			this.search('xxkq'); //分页获取默认数据
			
			this.isLoading = true; //动画开始
		},
		mounted() {
			//加载完成之后event
			this.isLoading = false; //动画结束
		},
		methods: {
			tabchk(tab) {
				if(tab.name == 'quanxiao') {
					this.sjshow = true
					this.sjshow1 = false
					this.sjshow2 = false
					this.search('xxkq')
					this.$nextTick(function() {
						this.drawPie1('kqtj1')
					});
				} else if(tab.name == 'laoshi') {
					this.sjshow = false
					this.sjshow1 = true
					this.sjshow2 = false
					this.search('lskq')
					this.$nextTick(function() {
						this.drawPie2('kqtj2')
					});
				} else if(tab.name == 'banji') {
					this.sjshow = false
					this.sjshow1 = false
					this.sjshow2 = true
					this.search('bjkq')
					this.$nextTick(function() {
						this.drawPie3('kqtj3')
					});
				}
			},
			drawPie1(id) {
				this.charts = echarts.init(document.getElementById(id))
				var sj = this.sj
				var kqrs = this.kqrs
				var qqrs = this.qqrs
				var cdrs = this.cdrs
				this.charts.setOption({
					title: {
						text: '考勤统计',
					},
					tooltip: {
						trigger: 'axis',
						formatter: function (data) { 
							var kqrs1 =''
							var qqrs1 =''
							var cdrs1 =''
							for(var i in sj){
								if(data[0].name == sj[i]){
									kqrs1 = kqrs[i]
									qqrs1 = qqrs[i]
									cdrs1 = cdrs[i]
								}
							}
							return data[0].name+"<br/> 出勤率 : "+data[0].value+'% <br/> 考勤人数 : '+kqrs1 +'<br/> 缺勤人数 : ' + qqrs1 +'<br/> 迟到人数 : ' + cdrs1
						},
					},
					legend: {
					},
					grid: {
						left: '3%',
						right: '4%',
						bottom: '3%',
						containLabel: true
					},
					toolbox: {
						feature: {
							saveAsImage: {}
						}
					},
					xAxis: {
						type: 'category',
						boundaryGap: false,
						data: this.sj
					},
					yAxis: [{
						type: 'value',
						name: '出勤率',
						min: 0,
						max: 100,
						position: 'left',
						axisLabel: {
							formatter: '{value} %'
						}

					}],
					series: [
						{
							name: '全校出勤率',
							type: 'line',
							stack: '总量',
							data: this.cqv,
						},
					]
				})
			},
			drawPie2(id) {
				this.charts = echarts.init(document.getElementById(id))
				var sj = this.sj
				var kqrc = this.kqrc
				var qqrc = this.qqrc
				var cqrc = this.cqrc
				this.charts.setOption({
					title: {
						text: '考勤统计',
					},
					tooltip: {
						trigger: 'axis',
						formatter: function (data) { 
							var kqrc1 =''
							var qqrc1 =''
							var cqrc1 =''
							for(var i in sj){
								if(data[0].name == sj[i]){
									kqrc1 = kqrc[i]
									qqrc1 = qqrc[i]
									cqrc1 = cqrc[i]
								}
							}
							return data[0].name+"<br/> 出勤率 : "+data[0].value+'% <br/> 考勤人数 : '+kqrc1 +'<br/> 缺勤人数 : ' + qqrc1 +'<br/> 出勤人数 : ' + cqrc1

						},
					},
					legend: {
					},
					grid: {
						left: '3%',
						right: '4%',
						bottom: '3%',
						containLabel: true
					},
					toolbox: {
						feature: {
							saveAsImage: {}
						}
					},
					xAxis: {
						type: 'category',
						boundaryGap: false,
						data: this.sj
					},
					yAxis: [{
						type: 'value',
						name: '出勤率',
						min: 0,
						max: 100,
						position: 'left',
						axisLabel: {
							formatter: '{value} %'
						}

					}],
					series: [
						{
							name: '全校出勤率',
							type: 'line',
							stack: '总量',
							data: this.cqv,
						},
					]
				})
			},
			drawPie3(id) {
				this.charts = echarts.init(document.getElementById(id))
				var sj = this.sj
				var kqrc = this.kqrc
				var qqrc = this.qqrc
				var cqrc = this.cqrc
				this.charts.setOption({
					title: {
						text: '考勤统计',
					},
					tooltip: {
						trigger: 'axis',
						formatter: function (data) { 
							var kqrc1 =''
							var qqrc1 =''
							var cqrc1 =''
							for(var i in sj){
								if(data[0].name == sj[i]){
									kqrc1 = kqrc[i]
									qqrc1 = qqrc[i]
									cqrc1 = cqrc[i]
								}
							}
							return data[0].name+"<br/> 出勤率 : "+data[0].value+'% <br/> 考勤人数 : '+kqrc1 +'<br/> 缺勤人数 : ' + qqrc1 +'<br/> 出勤人数 : ' + cqrc1

						},
					},
					legend: {
					},
					grid: {
						left: '3%',
						right: '4%',
						bottom: '3%',
						containLabel: true
					},
					toolbox: {
						feature: {
							saveAsImage: {}
						}
					},
					xAxis: {
						type: 'category',
						boundaryGap: false,
						data: this.sj
					},
					yAxis: [{
						type: 'value',
						name: '出勤率',
						min: 0,
						max: 100,
						position: 'left',
						axisLabel: {
							formatter: '{value} %'
						}

					}],
					series: [
						{
							name: '全校出勤率',
							type: 'line',
							stack: '总量',
							data: this.cqv,
						},
					]
				})
			},
			search(id) {
				var logininfo = JSON.parse(localStorage.logininfo);
				var params3 = qs.stringify({
					day: this.Day,
					code: id,
					lsid: '',
					bjtime: this.btime,
					edtime: this.etime,
					yhid: logininfo.id,
					xxid: logininfo.xxid,
				});
				this.searchLoading = true;
				this.axios.post(this.$store.state.api + 'ls/getlstj', params3)
					.then(res => {
						if(res.data.code == 1) {
						console.log(res, 999988887777)
						var list = res.data.data
						if(list){
							if(id == 'xxkq'){
								var cqv  = list.cqv.substr(0, list.cqv.length - 1)
								var sj   = list.sj.substr(0, list.sj.length - 1)
								var kqrs = list.kqrs.substr(0, list.kqrs.length - 1)
								var qqrs = list.qqrs.substr(0, list.qqrs.length - 1)
								var cdrs = list.cdrs.substr(0, list.cdrs.length - 1)
								this.cqv = cqv.split(",");
								this.sj  = sj.split(",");
								this.kqrs = kqrs.split(",");
								this.qqrs = qqrs.split(",");
								this.cdrs = cdrs.split(",");
								this.$nextTick(function() {
									this.drawPie1('kqtj1')
								});
						}
						if(id == 'lskq'){
							var cqv = list.cqv.substr(0, list.cqv.length - 1)
							var sj = list.sj.substr(0, list.sj.length - 1)
							var kqrc = list.kqrc.substr(0, list.kqrc.length - 1)
							var qqrc = list.qqrc.substr(0, list.qqrc.length - 1)
							var cqrc = list.cqrc.substr(0, list.cqrc.length - 1)
							this.cqv = cqv.split(",");
							this.sj = sj.split(",");
							this.kqrc = kqrc.split(",");
							this.qqrc = qqrc.split(",");
							this.cqrc = cqrc.split(",");
							this.$nextTick(function() {
								this.drawPie2('kqtj2')
							});
						}
						if(id == 'bjkq'){
							var cqv = list.cqv.substr(0, list.cqv.length - 1)
							var sj = list.sj.substr(0, list.sj.length - 1)
							var kqrc = list.kqrc.substr(0, list.kqrc.length - 1)
							var qqrc = list.qqrc.substr(0, list.qqrc.length - 1)
							var cqrc = list.cqrc.substr(0, list.cqrc.length - 1)
							this.cqv = cqv.split(",");
							this.sj = sj.split(",");
							this.kqrc = kqrc.split(",");
							this.qqrc = qqrc.split(",");
							this.cqrc = cqrc.split(",");
							this.$nextTick(function() {
									this.drawPie3('kqtj3')
								});
						}
						}
						}else {
							this.sjshow1=false;
							this.sjshow2=false;
							this.$message.warning(res.data.msg);
						}
						
						this.searchLoading = false;
					}).catch(res => {
						console.log(res)
						this.searchLoading = false;
					})
			},
			

			/* 组件的弹框  */
			componentsShow(type, data) { //显示组件
				for(let i in this.portComponents) {
					if(type == this.portComponents[i].type) {
						this.portComponents[i].toggle = true;
						this.portComponents[i].params = data;
						if(this.portComponents[i].data.type == 'single') {
							this.portComponents[i].data.index = data.row.id
						} else if(this.portComponents[i].data.type == 'multiple') {
							this.portComponents[i].data.index = this.multipleDelNum;
						} else {
							return;
						}
						return;
					}
				}
			},
			componentsHide(setting) { //关闭组件
				for(let i in this.portComponents) {
					if(setting.type == this.portComponents[i].type) {
						this.portComponents[i].toggle = false;
						if(!setting.cancel) {
							this.search();
						}
						return;
					}
				}
			}
		},
		computed: {
			...mapState([
				'api' //域名
			]),
			multipleDeleteDisabled() {
				// console.log(this.multipleDelNum)
				if(this.multipleDelNum) {
					return false;
				} else {
					return true
				}
			}
		}
	}
</script>

<style lang="less" scoped>
	.port-page {
		font-size: 12px;
		.btn {
			height: 30px;
			padding: 0 10px;
		}
		.code-search {
			height: 30px;
			margin: 10px 0 10px 0;
			min-width: 100px;
			max-width: 135px;
		}
		.class-page {
			text-align: left;
			margin-top: 10px;
		}
		.search-item {
			display: inline-block;
			margin-right: 10px;
		}
		.but1 {
			width: 100%;
			float: left;
		}
		.search {
			width: 77%;
			float: right;
			text-align: right;
		}
		.el-button+.el-button {
			margin-left: 0px;
			margin-top: 8px;
		}
	}
</style>